{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gurobipy import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "m = Model(\"lp2\")\n",
    "\n",
    "# create variables\n",
    "x = m.addVar(vtype=GRB.CONTINUOUS, name=\"x\")\n",
    "y = m.addVar(vtype=GRB.CONTINUOUS, name=\"y\")\n",
    "\n",
    "m.setObjective(0.4*x+0.5*y, GRB.MINIMIZE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<gurobi.Constr *Awaiting Model Update*>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# add constraints\n",
    "m.addConstr(0.3*x + 0.1*y <=2.7, \"c0\")\n",
    "m.addConstr(0.5*x + 0.5*y == 6, \"c1\")\n",
    "m.addConstr(0.6*x + 0.4*y >=6, \"c2\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Optimize a model with 3 rows, 2 columns and 6 nonzeros\n",
      "Coefficient statistics:\n",
      "  Matrix range     [1e-01, 6e-01]\n",
      "  Objective range  [4e-01, 5e-01]\n",
      "  Bounds range     [0e+00, 0e+00]\n",
      "  RHS range        [3e+00, 6e+00]\n",
      "Presolve removed 3 rows and 2 columns\n",
      "Presolve time: 0.00s\n",
      "Presolve: All rows and columns removed\n",
      "Iteration    Objective       Primal Inf.    Dual Inf.      Time\n",
      "       0    5.2500000e+00   0.000000e+00   0.000000e+00      0s\n",
      "\n",
      "Solved in 0 iterations and 0.01 seconds\n",
      "Optimal objective  5.250000000e+00\n"
     ]
    }
   ],
   "source": [
    "m.optimize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x 7.500000000000001\n",
      "y 4.499999999999999\n"
     ]
    }
   ],
   "source": [
    "for v in m.getVars():\n",
    "    print(v.varName, v.x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "m.write('test.lp')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
